package com.example.backend.api.controller;


import com.example.backend.api.common.Result;
import com.example.backend.api.service.impl.AdminServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xwyzsn
 * @since 2023-03-07
 */
@RestController
@RequestMapping("/api/admin")
@CrossOrigin(origins = "*",maxAge = 3600)
public class AdminController {

    @Autowired
    private AdminServiceImpl adminService;
    @PostMapping("/login")
    public Result login(@RequestParam(value = "username",required = false ) String id,@RequestParam(value = "password",required = false) String password){
        return adminService.login(id,password);
    }
    @GetMapping("selectAll")
    public Result selectAll(){
        return adminService.selectAll();
    }

    @GetMapping("delete")
    public Result delete(@RequestParam(value = "user_id") String id){
        return adminService.delete(id);
    }
    @PostMapping("update")
    public Result update(@RequestParam(value = "user_id") String id,
                         @RequestParam(value = "name" ,required = false) String name,
                         @RequestParam(value = "tel",required = false) String tel){
        return adminService.update(id,name,tel);
    }
    @PostMapping("add")
    public Result add(@RequestParam(value = "user_id") String id,
                      @RequestParam(value = "name" ,required = false) String name,
                      @RequestParam(value = "tel",required = false) String tel){
        return adminService.add(id,name,tel);
    }

    @PostMapping("changePassword")
    public Result changePassword(@RequestParam(value = "user_id") String id,
                                 @RequestParam(value = "oldPassword") String oldPassword,
                                 @RequestParam(value = "newPassword") String newPassword){
        return adminService.changePassword(id,oldPassword,newPassword);
    }
}
